<?php
defined('is_running') or die('Not an entry point...');
require("init.php");

if (isset($_POST['submit'])) {
    if ($_POST['submit'] == "Add")
        addCategories($_POST['cat_name']);

    if ($_POST['submit'] == "Del")
        delCategories($_POST['cat_id']);
}
$cat_lines = readData($cat_data);
?>

<table id="default_table">
    <tr>
        <th width="90%">Category</th>
        <th>&nbsp;</th>
    </tr>
    <?php
    $cat_lines = readData($cat_data);

    foreach ($cat_lines as $cat_line) {
        list($cat_id, $cat_name) = explode("|", $cat_line);
        if ($i2 % 2 > 0) {
            echo '<tr id="row_even">';
        } else {
            echo '<tr id="row_odd">';
        }
        $i2++;
    ?>
            <td><?php echo $cat_name; ?></td>
            <td><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                    <input type="hidden" name="cat_id" value="<?php echo $cat_id; ?>" />
                    <input type="submit" value="Del" name="submit"/></form>
            </td>
        </tr>
    <?php } ?>

    <tr>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <td><input type="text" name="cat_name" size="50" /></td>
        <td><input type="submit" value="Add" name="submit" /></td>
    </form>

</tr>
</table>
